package com.rey.demo.link;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.data.Stat;

/**
 * @ClassName: CuratorDemo
 * @Description: TODO
 * @Author reyJojo
 * @Date 2021/12/2 19:32
 * @Version 1.0
 */
public class CuratorDemo {
    public static void main(String[] args) throws Exception {
        CuratorFramework curatorFramework= CuratorFrameworkFactory.
                builder()
                .connectString("39.104.13.176:2181")
                .sessionTimeoutMs(4000)
                .retryPolicy(new ExponentialBackoffRetry(1000,3))
                .namespace("").build();
        curatorFramework.start();
        Stat stat=new Stat();
        //查询节点数据
        byte[] bytes = curatorFramework.getData().storingStatIn(stat).forPath("/runoob");
        System.out.println(new String(bytes));
        curatorFramework.close();
    }

    public CuratorFramework link4CuratorApi() throws Exception {
        CuratorFramework curatorFramework= CuratorFrameworkFactory.
                builder()
                .connectString("39.104.13.176:2181")
                .sessionTimeoutMs(4000)
                .retryPolicy(new ExponentialBackoffRetry(1000,3))
                .namespace("").build();
        curatorFramework.start();
        return curatorFramework;
    }
}
